package com.mall.service.impl;

import com.mall.entity.MmallAdvert;
import com.mall.mapper.MmallAdvertMapper;
import com.mall.service.MmallAdvertService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ppmall
 * @since 2021-09-19
 */
@Service
public class MmallAdvertServiceImpl extends ServiceImpl<MmallAdvertMapper, MmallAdvert> implements MmallAdvertService {

    @Autowired
    private RedisUtil redisUtil;

    @Override
    public boolean updateAdvertById(MmallAdvert advert) {
        int update = baseMapper.updateById(advert);
        if(update > 0) {
            String redis_cache_name = "allAdvert";
            redisUtil.del(redis_cache_name);
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean saveAdvert(MmallAdvert advert) {
        int insert = baseMapper.insert(advert);
        if(insert > 0) {
            String redis_cache_name = "allAdvert";
            redisUtil.del(redis_cache_name);
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean deleteAdvertById(Integer id) {
        int delete = baseMapper.deleteById(id);
        if(delete > 0) {
            String redis_cache_name = "allAdvert";
            redisUtil.del(redis_cache_name);
            return true;
        } else {
            return false;
        }
    }
}
